package com.hmyd.hmyd_android.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.dto.LatestDto;
import com.hmyd.hmyd_android.utils.Utils;

/**
 * 最新动态
 * 
 * @author wangc
 * 
 */
public class LatestAdapter extends BaseAdapter {
	private Context mContext;
	private List<LatestDto> lists;
	private LayoutInflater mInflater;

	public LatestAdapter(Context context, List<LatestDto> lists) {
		this.mContext = context;
		this.lists = lists;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return lists != null ? lists.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_latest_events_item, null);
			holder = new ViewHolder();

			holder.tv_title = (TextView) convertView.findViewById(R.id.popular_event_title);
			holder.tv_time = (TextView) convertView.findViewById(R.id.popular_event_time);
			holder.imageView = (ImageView) convertView.findViewById(R.id.latest_event_pic);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		
		LatestDto item = lists.get(position);
		holder.tv_title.setText(item.title);
		holder.tv_time.setText(Utils.getDateString(item.createdTime));
		holder.imageView.setTag(item.imgUrl);
		if (holder.imageView.getTag() != null && holder.imageView.getTag().equals(item.imgUrl)) {
			AppBasic.getBitmapUtils(mContext).display(holder.imageView, item.imgUrl);
		}
		return convertView;

	}

	class ViewHolder {
		public TextView tv_title;
		public TextView tv_time;
		public TextView tv_content;
		public ImageView imageView;
		public View line;
		ImageView redView;

	}
}
